package com.csxy.six.controller;

import com.csxy.six.R2;
import com.csxy.six.entity.User;
import com.csxy.six.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user-center")
@Tag(name = "用户中心", description = "用户中心相关功能")
@SecurityRequirement(name = "JWT")
public class UserCenterController {

    @Autowired
    private UserService userService;

    @GetMapping("/profile")
    @Operation(summary = "获取个人资料", description = "获取当前登录用户的个人资料")
    public R2<User> getProfile() {
        return userService.getCurrentUserProfile();
    }

    @PutMapping("/profile")
    @Operation(summary = "更新个人资料", description = "更新当前登录用户的个人资料")
    public R2<User> updateProfile(@RequestBody @Parameter(description = "用户资料") User user) {
        return userService.updateCurrentUserProfile(user);
    }

    @PostMapping("/change-password")
    @Operation(summary = "修改密码", description = "修改当前用户的登录密码")
    public R2<Void> changePassword(
            @RequestParam @Parameter(description = "旧密码") String oldPassword,
            @RequestParam @Parameter(description = "新密码") String newPassword) {
        return userService.changePassword(oldPassword, newPassword);
    }
}